package com.yssoft.utils;

import com.yssoft.shiro.MyRealm.ShiroUser;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.session.Session;

public class UserHelper {
	/**
	 * 获取当前登录用户信息.
	 */
	public static ShiroUser getCurrentUser() {
        Session session = SecurityUtils.getSubject().getSession();
	    return (ShiroUser) session.getAttribute(SessionUtil.USER_SESSION);
	}

	/**
	 * 取出Shiro中的当前用户Id.
	 */
	public static Integer getCurrentUserId() {
        Session session = SecurityUtils.getSubject().getSession();
		ShiroUser user = (ShiroUser) session.getAttribute(SessionUtil.USER_SESSION);

		if (null != user) {
			return user.getId();
		}

		return null;
	}

	/**
	 * 取出Shiro中的当前用户企业Id.
	 */
	public static Integer getCurrentCompanyId() {
        Session session = SecurityUtils.getSubject().getSession();
		ShiroUser user = (ShiroUser) session.getAttribute(SessionUtil.USER_SESSION);

		if (null != user) {
			return user.getEntId();
		}

		return null;
	}
	/**
	 * 取出Shiro中的当前用户部门Id.
	 */
	public static Integer getCurrentDeptId() {
        Session session = SecurityUtils.getSubject().getSession();
		ShiroUser user = (ShiroUser)  session.getAttribute(SessionUtil.USER_SESSION);

		if (null != user) {
			return user.getDeptId();
		}

		return null;
	}
}
